﻿using MS_Enitity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MS_UI
{
    public partial class PortFrm : Form
    {
        public PortFrm()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            ControlStatusUpdate();


        }

        private void PortFrm_Load(object sender, EventArgs e)
        {
            timer1.Interval = 100;
            timer1.Enabled = true;
            ControlStatusUpdate();
        }


        private void ControlStatusUpdate()
        {
            Carrier1_ID.Text = CommMethods.SPort1_carrierID;
            Carrier2_ID.Text = CommMethods.SPort2_carrierID;
            Lot1_ID.Text = CommMethods.SPort1_lotID;
            Lot2_ID.Text = CommMethods.SPort2_lotID;

            foreach (Control item in Controls)
            {


                if (item is Label && (string)((Label)item).Tag != null)
                {

                    string VarName = (string)(((Label)item).Tag);
                    Int16_Variable var = CommMethods.Int16_Variable_List.Find(delegate (Int16_Variable v) { return v.VarName == VarName; });
                    int index = CommMethods.Int16_Variable_List.IndexOf(var);
                    index += 1;
                    //Int16_Variable var2 = CommMethods.Int16_Variable_List[index];
                    if (var != null)
                    {
                        if (var.IsInt32 == "Y")
                        {
                            Int16_Variable var2 = CommMethods.Int16_Variable_List[index];
                            int[] values = new int[2];
                            values[0] = Convert.ToInt32(CommMethods.CurrentValue[VarName]);
                            values[1] = Convert.ToInt32(CommMethods.CurrentValue[var2.VarName]);
                            int intvalue = (values[0] & 0xffff) | (values[1] << 16);
                            float floatvalue = ((float)intvalue) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO)));
                            ((Label)item).Text = Convert.ToString(floatvalue);
                        }

                        if (var.IsInt32 == "N")
                        {

                           string sPort1_NO = Convert.ToString(float.Parse(CommMethods.CurrentValue["端口1号码"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                           string  sPort1_Type= Convert.ToString(float.Parse(CommMethods.CurrentValue["端口1形态"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string  sPort1_Status= Convert.ToString(float.Parse(CommMethods.CurrentValue["端口1状态"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string   sCarrier1_Status= Convert.ToString(float.Parse(CommMethods.CurrentValue["载具1状态"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string   sCV1_Mode= Convert.ToString(float.Parse(CommMethods.CurrentValue["端口1搬运模式"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string  sLot1_NO= Convert.ToString(float.Parse(CommMethods.CurrentValue["端口1数量"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                           
                            string sPort2_NO = Convert.ToString(float.Parse(CommMethods.CurrentValue["端口2号码"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string sPort2_Type = Convert.ToString(float.Parse(CommMethods.CurrentValue["端口2形态"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string sPort2_Status = Convert.ToString(float.Parse(CommMethods.CurrentValue["端口2状态"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string sCarrier2_Status = Convert.ToString(float.Parse(CommMethods.CurrentValue["载具2状态"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string sCV2_Mode = Convert.ToString(float.Parse(CommMethods.CurrentValue["端口2搬运模式"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));
                            string sLot2_NO = Convert.ToString(float.Parse(CommMethods.CurrentValue["端口2数量"]) / Convert.ToSingle(Math.Pow(10, Convert.ToInt32(var.PointNO))));

                            Port1_NO.Text = sPort1_NO;
                            Lot1_NO.Text = sLot1_NO;
                            Port2_NO.Text = sPort2_NO;
                            Lot2_NO.Text = sLot2_NO;



                            switch (sPort1_Type)
                            {
                                case "0":
                                     Port1_Type.Text  = "投板";
                                    break;
                                case "1":
                                    Port1_Type.Text= "收板";
                                    break;
                                default:
                                    break;
                            }

                            switch (sPort1_Status)
                            {
                                case "0":
                                    Port1_Status.Text = "";
                                    break;
                                case "1":
                                    Port1_Status.Text = "搬入请求";
                                    break;
                                case "2":
                                    Port1_Status.Text = "搬入完成";
                                    break;
                                case "3":
                                    Port1_Status.Text = "卸除请求";
                                    break;
                                case "4":
                                    Port1_Status.Text = "卸除完成";
                                    break;
                                default:
                                    break;
                            }

                            switch (sCarrier1_Status)
                            {
                                case "0":
                                    Carrier1_Status.Text = "未生产";
                                    break;
                                case "1":
                                    Carrier1_Status.Text = "数据请求";
                                    break;
                                case "2":
                                    Carrier1_Status.Text = "等待生产";
                                    break;
                                case "3":
                                    Carrier1_Status.Text = "生产中";
                                    break;
                                case "4":
                                    Carrier1_Status.Text = "生产结束";
                                    break;
                                case "5":
                                    Carrier1_Status.Text = "生产异常结束";
                                    break;
                                case "6":
                                    Carrier1_Status.Text = "投板询问";
                                    break;
                                case "7":
                                    Carrier1_Status.Text = "投板询问重试";
                                    break;
                                case "8":
                                    Carrier1_Status.Text = "首检生产中";
                                    break;
                                case "9":
                                    Carrier1_Status.Text = "首检完成等待确认";
                                    break;
                                case "10":
                                    Carrier1_Status.Text = "载具取消需要退走";
                                    break;

                                case "11":
                                    Carrier1_Status.Text = "载具取消需人员确认";
                                    break;
    
                                default:
                                    break;
                            }

                            switch (sCV1_Mode)
                            {
                                case "0":
                                    CV1_Mode.Text = "MGV";
                                    break;
                                case "1":
                                    CV1_Mode.Text = "AGV";
                                    break;
                              
                                default:
                                    break;
                            }




                            switch (sPort2_Type)
                            {
                                case "0":
                                    Port2_Type.Text = "投板";
                                    break;
                                case "1":
                                    Port2_Type.Text = "收板";
                                    break;
                                default:
                                    break;
                            }

                            switch (sPort2_Status)
                            {
                                case "0":
                                    Port2_Status.Text = "";
                                    break;
                                case "1":
                                    Port2_Status.Text = "搬入请求";
                                    break;
                                case "2":
                                    Port2_Status.Text = "搬入完成";
                                    break;
                                case "3":
                                    Port2_Status.Text = "卸除请求";
                                    break;
                                case "4":
                                    Port2_Status.Text = "卸除完成";
                                    break;
                                default:
                                    break;
                            }

                            switch (sCarrier2_Status)
                            {
                                case "0":
                                    Carrier2_Status.Text = "未生产";
                                    break;
                                case "1":
                                    Carrier2_Status.Text = "数据请求";
                                    break;
                                case "2":
                                    Carrier2_Status.Text = "等待生产";
                                    break;
                                case "3":
                                    Carrier2_Status.Text = "生产中";
                                    break;
                                case "4":
                                    Carrier2_Status.Text = "生产结束";
                                    break;
                                case "5":
                                    Carrier2_Status.Text = "生产异常结束";
                                    break;
                                case "6":
                                    Carrier2_Status.Text = "投板询问";
                                    break;
                                case "7":
                                    Carrier2_Status.Text = "投板询问重试";
                                    break;
                                case "8":
                                    Carrier2_Status.Text = "首检生产中";
                                    break;
                                case "9":
                                    Carrier2_Status.Text = "首检完成等待确认";
                                    break;
                                case "10":
                                    Carrier2_Status.Text = "载具取消需要退走";
                                    break;

                                case "11":
                                    Carrier2_Status.Text = "载具取消需人员确认";
                                    break;

                                default:
                                    break;
                            }

                            switch (sCV2_Mode)
                            {
                                case "0":
                                    CV2_Mode.Text = "MGV";
                                    break;
                                case "1":
                                    CV2_Mode.Text = "AGV";
                                    break;

                                default:
                                    break;
                            }










                        }

                    }

                }
            }
        }








        private void Port1_NO_Click(object sender, EventArgs e)
        {

        }

        private void Port1_Status_Click(object sender, EventArgs e)
        {

        }
    }
}
